package com.ruoyi.web.controller.basedata;

import com.ruoyi.basedata.domain.Replace;
import com.ruoyi.basedata.service.IReplaceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 换记录Controller
 *
 * @author ruoyi
 * @date 2023-09-07
 */
@RestController
@RequestMapping("/basedata/replace")
public class ReplaceController extends BaseController {
    @Autowired
    private IReplaceService replaceService;


    /**
     * 查询换记录列表
     */
    @PreAuthorize("@ss.hasAnyPermi('basedata:replace:list,logs:exchange:list')")
    @GetMapping("/list")
    public TableDataInfo list(Replace replace) {
        startPage();
        List<Replace> list = replaceService.selectReplaceList(replace);
        return getDataTable(list);
    }

    /**
     * 查询换记录列表
     */
    @PreAuthorize("@ss.hasAnyPermi('basedata:replace:list,logs:exchange:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(Replace replace) {
        startPage();
        List<Replace> list = replaceService.selectList(replace);
        return getDataTable(list);
    }

    /**
     * 导出换记录列表
     */
    @PreAuthorize("@ss.hasAnyPermi('basedata:replace:export,logs:exchange:list')")
    @Log(title = "换表记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Replace replace) {
        List<Replace> list = replaceService.selectReplaceList(replace);
        ExcelUtil<Replace> util = new ExcelUtil<Replace>(Replace.class);
        util.exportExcel(response, list, "换记录数据");
    }

    /**
     * 获取换记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:replace:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(replaceService.selectReplaceByID(ID));
    }

    /**
     * 新增换记录
     */
    @PreAuthorize("@ss.hasPermi('basedata:replace:add')")
    @Log(title = "换表记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Replace replace) {
        return toAjax(replaceService.insertReplace(replace));
    }

    /**
     * 修改换记录
     */
    @PreAuthorize("@ss.hasPermi('basedata:replace:edit')")
    @Log(title = "换表记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Replace replace) {
        return toAjax(replaceService.updateReplace(replace));
    }

    /**
     * 删除换记录
     */
    @PreAuthorize("@ss.hasPermi('basedata:replace:remove')")
    @Log(title = "换表记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs) {
        return toAjax(replaceService.deleteReplaceByIDs(IDs));
    }
}
